package cn.e4j.modular.api.controller;

import cn.e4j.core.dto.impl.Dto;
import cn.e4j.core.dto.requestDtoResolver.DtoParam;
import cn.e4j.core.dto.requestDtoResolver.DtoWapper;
import cn.e4j.core.reqres.response.ErrorResponseData;
import cn.e4j.core.reqres.response.ResponseData;
import cn.e4j.core.reqres.response.SuccessResponseData;
import cn.e4j.core.util.DateUtils;
import cn.e4j.modular.api.service.GwbService;
import cn.e4j.modular.api.service.JdcxService;
import cn.e4j.modular.api.util.ControllerSupport;
import cn.e4j.modular.system.entity.SysUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yu_huan on 2018/4/16.
 */
@RestController
@RequestMapping("api/wx/jdcx")
public class JdcxController extends ControllerSupport {

    @Autowired
    private JdcxService jdcxService;

    @Autowired
    GwbService gwbService;

    /**
     * 获取进度列表
     *
     * @return
     */
    @RequestMapping(value = "getProgressListData")
    public ResponseData getProgressListData(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        SysUser user = wapper.getSysUser();
        try {
            inDto.put("MMRD004", DateUtils.parseDate(inDto.getString("MMRD004")));
            inDto.put("MMRDENT",inDto.getString("ENT"));

            if (inDto.getString("GWAA007").equals("0")){
                //内部员工
                inDto.put("USERID", user.getID());

                //客户权限
                inDto.put("GWAK006", "1");
                Dto gwb001 = gwbService.getGwb001(user,inDto);
                List<Dto> _list = (List<Dto>) gwb001.get("CUSTOMERS");
                inDto.put("CUSTOMERS", _list);
            }else if (inDto.getString("GWAA007").equals("1")){
//                List<Dto> clist = new ArrayList<Dto>();
//                Dto dto = new Dto();
//                dto.put("ID",inDto.getString("GWAK030"));
//                clist.add(dto);
//                inDto.put("CUSTOMERS",clist);
            }

            list = jdcxService.getProgressListData(wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
           return ERROR;
        }

        return SUCCESS(list);
    }

    @RequestMapping(value = "getProgressDeatilListPage")
    public ResponseData getProgressDeatilListPage(@DtoParam DtoWapper wapper) {
        Dto inDto = wapper.getDto();
        List<Dto> list = new ArrayList<Dto>();
        SysUser user = wapper.getSysUser();
        try {
            inDto.put("MMRD004", DateUtils.parseDate(inDto.getString("MMRD004")));
            inDto.put("MMRDENT",inDto.getString("ENT"));

            if (inDto.getString("GWAA007").equals("0")){
                //内部员工
                inDto.put("USERID", user.getID());

                //客户权限
                inDto.put("GWAK006", "1");
                Dto gwb001 = gwbService.getGwb001(user,inDto);
                List<Dto> _list = (List<Dto>) gwb001.get("CUSTOMERS");
                inDto.put("CUSTOMERS", _list);
            }else if (inDto.getString("GWAA007").equals("1")){
//                List<Dto> clist = new ArrayList<Dto>();
//                Dto dto = new Dto();
//                dto.put("ID",inDto.getString("GWAK030"));
//                clist.add(dto);
//                inDto.put("CUSTOMERS",clist);
            }

            list = jdcxService.getProgressDeatilListPage(wapper.getPage(),inDto);
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }

        return SUCCESS(list);
    }
}
